package net.aiform.security.action;

import javax.servlet.http.HttpServletRequest;

import net.aiform.bean.Constant;
import net.aiform.bean.JSONMessage;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;

public class SecurityAction implements Preparable, ServletRequestAware {
	private JSONMessage json;
	private HttpServletRequest req;
	private String arg1;

	public SecurityAction() {
		this.json = new JSONMessage();
	}

	public String execute() {
		return Action.SUCCESS;
	}

	public String checkCertCode() {
		String codePage = this.arg1;
		String codeServer = (String) this.req.getSession().getAttribute(Constant.CERTPIC);
		if (!(codePage.equalsIgnoreCase(codeServer))) {
			json.setCode("-1");
		}
		return Action.SUCCESS;
	}

	@JSON(serialize = false)
	public String getArg1() {
		return arg1;
	}

	public void setArg1(String arg1) {
		this.arg1 = arg1;
	}

	@Override
	public void prepare() throws Exception {

	}

	public JSONMessage getJson() {
		return json;
	}

	public void setJson(JSONMessage json) {
		this.json = json;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.req = request;
	}
}
